﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BIS.Utility.DAL;
using BIS.Portal.Modules.CMS.Entity;
using BIS.Utility.DAL.DataMapper;

namespace BIS.Portal.Modules.CMS.DAL
{
    public class AdminCmsArticleInCategoryDAL
    {
        /// Get Category
        /// </summary>
        /// <param name="articleId">The article id.</param>
        /// <param name="status">The status.</param>
        public static IList<AdminCmsArticleInCategoryEntity> GetCategoryId(int articleId)
        {
            IList<AdminCmsArticleInCategoryEntity> list = new List<AdminCmsArticleInCategoryEntity>();
            using (IDataReader reader = SqlHelper.ExecuteReader(DALConnection.ConnectionString,
                                                                CommandType.StoredProcedure,
                                                                "BIS_sCMS_ARTICLE_GetCategoryId",
                                                                new SqlParameter("@articleId", articleId)))
            {
                list = EntityMapper.FillCollection<AdminCmsArticleInCategoryEntity>(reader);
            }


            return list;
        }

        /// <summary>
        /// Delete 
        /// </summary>
        /// <param name="articleId"></param>
        /// <returns></returns>
        public static int DeleteData(int articleId)
        {
            return SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString, CommandType.StoredProcedure,
                                             "BIS_sCMS_ARTICLE_IN_CATEGORY_DeleteData",
                                             new SqlParameter("@article_id", @articleId));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmsArticleInCategoryEntity"></param>
        /// <returns></returns>
        public static int InsertData(AdminCmsArticleInCategoryEntity entity)
        {
            
            SqlParameter[] param = new SqlParameter[]
                                       {
                                           new SqlParameter("@article_in_category",entity.Article_in_category),
                                           new SqlParameter("@article_id",entity.Article_id),
                                           new SqlParameter("@category_id", entity.Category_id), 
                                           new SqlParameter("@article_priority",entity.Article_priority), 
                                           new SqlParameter("@is_primary_category",entity.Is_primary_category)};
            
            int i = SqlHelper.ExecuteNonQuery(DALConnection.ConnectionString,
                                              CommandType.StoredProcedure, "BIS_sCMS_ARTICLE_IN_CATEGORY_InsertData",
                                              param);

            return i;

        }
    }
}
